package com.navigationtest;

import android.view.View;

import com.hjq.bar.OnTitleBarListener;
import com.myatest.BR;
import com.myatest.R;
import com.pbase.tools.Logger;
import com.pbase.ui.page.DataBindingConfig;

import androidx.activity.OnBackPressedCallback;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

/**
 * User: psn
 * Date: 2021/12/11
 */
public class Test6Fragment extends NavigationViewFragment {
    private Test6ViewModel mViewModel;
    @Override
    protected void onCreateViewBefore() {

    }

    @Override
    protected void onCreateViewAfter() {
        requireActivity().getOnBackPressedDispatcher().addCallback(new OnBackPressedCallback(true) {
            @Override
            public void handleOnBackPressed() {
                //拦截返回事件
//            moveTaskToBack(true);
                left();

            }
        });
    }

    @Override
    protected void initViewModel() {
        mViewModel =getFragmentScopeViewModel(Test6ViewModel.class);
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        return new DataBindingConfig(R.layout.frg_text6, BR.vm,mViewModel)
                .addBindingParam(BR.OnTitleBarListener,new TitleBarListener())
                .addBindingParam(BR.click,new Click());
    }
    public class Click {
        public void  btn_a(View view){
            NavController controller = Navigation.findNavController( view);//找到button归属的controller
            controller.navigate(R.id.action_test6Fragment_to_test4Fragment);

        }


    }
    public class TitleBarListener implements OnTitleBarListener {

        @Override
        public void onLeftClick(View view) {
            Logger.e(getClass(),"onLeftClick");
//            getParentFragmentManager().popBackStack();
            left();
        }


        @Override
        public void onTitleClick(View view) {

        }

        @Override
        public void onRightClick(View view) {

        }
    }



}
